<template>
  <div class="detail-content">
    <video-player
      class="video-player vjs-custom-skin"
      ref="videoPlayer"
      :playsinline="true"
      :options="playerOptions"
    >
    </video-player>
    <div class="video-button" @click="handleClose">
      <i class="el-icon-close"></i>
    </div>
  </div>
</template>

<script>
import { videoPlayer } from "vue-video-player";
import "video.js/dist/video-js.css";
import "vue-video-player/src/custom-theme.css";
import "videojs-contrib-hls";
import { stopVideoUrl } from "@/api/video";

export default {
  components: { videoPlayer },
  props: {
    videoUrl: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      data: {},
      playerOptions: {
        autoplay: false, // 如果true,浏览器准备好时开始回放。
        muted: false, // 默认情况下将会消除任何音频。
        loop: false, // 导致视频一结束就重新开始。
        preload: "auto", // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频（如果浏览器支持）
        language: "zh-CN",
        aspectRatio: "16:9",
        fluid: true, // 当true时，Video.js player将拥有流体大小。换句话说，它将按比例缩放以适应其容器。
        techOrder: ["html5"], // 兼容顺序
        html5: { hls: { withCredentials: false } },
        sources: [
          {
            // type: "application/x-mpegURL",
            // src: "https://live.cgtn.com/1000/prog_index.m3u8",
            // type: "video/mp4",
            // src: require("./shipin.mp4"),
            // type: "application/mp4",
            // src: this.videoUrl,
            type: "video/x-mpegURL",
            // src: "http://47.96.65.45:1108/radar/media/1662002843164.mp4",
            src: "http://47.96.65.45:1108/1662011585797.mp4",
          },
        ],
        poster: "", //你的封面地址
        notSupportedMessage: "此视频暂无法播放，请稍后再试", // 允许覆盖Video.js无法播放媒体源时显示的默认信息。
        controlBar: {
          timeDivider: true,
          durationDisplay: true,
          remainingTimeDisplay: false,
          fullscreenToggle: true, //全屏按钮
        },
      },
    };
  },
  methods: {
    open(row = {}) {
      this.data = row;
      this.dialogVisible = true;
    },
    close() {
      stopVideoUrl().then(() => {});
      this.dialogVisible = false;
    },
    handleStart() {
      const player = this.$refs.videoPlayer.player;
      player.play();
    },
    handleStop() {
      const player = this.$refs.videoPlayer.player;
      player.pause();
    },
    handlePhoto() {
      const player = this.$refs.videoPlayer.player;
      player.pause();
    },
    handleClose() {
      this.$emit("videoClose");
    },
  },
};
</script>

<style lang="scss" scoped>
.detail-content {
  position: relative;
  background-color: rgba(200, 200, 200, 0.5);
  .video-button {
    position: absolute;
    width: 25px;
    height: 25px;
    right: 0;
    top: 0;
    color: #fff;
    background-color: rgba(255, 255, 255, 0.3);
    text-align: center;
    line-height: 25px;
    cursor: pointer;
    z-index: 1000;
  }
}
</style>
